﻿using System;
using System.Collections.Generic;
using System.Text;
using EnvDTE;
using TSVNAddin.SVN;
using EnvDTE80;

namespace TSVNAddin.Core
{
	public class EventDispatcherFactory
	{
		public EventDispatcher CreateEventDispatcher(DTE2 dte)
		{
			var events = (Events2)dte.Events;

			var versionControl = new SVNClientAdapter();
			var fileStorage = new FileSystemAdapter();

			var addedAction = new PathAddedAction(versionControl, fileStorage);
			var removedAction = new PathRemovedAction(versionControl);
			var renamedAction = new PathRenamedAction(versionControl, fileStorage);
			var projectAddedAction = new ProjectAddedAction(addedAction, new ProjectItemsRecover(), versionControl);

			var solutionActionExecutor = new SolutionActionExecutor(new SolutionAdapter(dte), renamedAction);
			var itemActionExecutor = new ItemActionExecutor(addedAction, removedAction, renamedAction);
			var projectActionExecutor = new ProjectActionExecutor(projectAddedAction, removedAction, renamedAction);

			var eventDispatcher = new EventDispatcher(events.SolutionEvents, events.ProjectItemsEvents);

			eventDispatcher.AddSolutionEventListener(solutionActionExecutor);
			eventDispatcher.AddProjectEventListener(projectActionExecutor);
			eventDispatcher.AddItemEventListener(itemActionExecutor);

			return eventDispatcher;
		}
	}
}
